--技能名
local zhaowendaoyi_other = fk.CreateSkill{
name = "mcdh_zhaowendaoyi_other&"
}

zhaowendaoyi_other:addEffect('active',{
    can_use = function(self, player)
        if  not player:isKongcheng() then
            return table.find(Fk:currentRoom().alive_players, function(p) return
            p:hasSkill("mcdh_zhaowendaoyi") and p:usedSkillTimes("mcdh_zhaowendaoyi",Player.HistoryPhase) == 0 and player:canPindian(p) end)
        end
    end,
    card_num = 0,
    target_num = 1,
    card_filter = Util.FalseFunc,
    target_filter = function(self, player,to_select, selected, selected_cards)
        local to = to_select
        return #selected == 0 and to:hasSkill("mcdh_zhaowendaoyi") and to:usedSkillTimes("mcdh_zhaowendaoyi",Player.HistoryPhase) == 0 and player:canPindian(to)
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local pindian = player:pindian({target}, self.name)
        target:setSkillUseHistory("mcdh_zhaowendaoyi", target:usedSkillTimes("mcdh_zhaowendaoyi",Player.HistoryPhase)+1,Player.HistoryPhase)

       local pindian = player:pindian({target}, self.name)
        if pindian.results[target].winner then
            local ids = {}
            for _, card in ipairs({pindian.fromCard, pindian.results[target].toCard}) do
                if room:getCardArea(card) == Card.DiscardPile then
                    table.insertIfNeed(ids, card:getEffectiveId())
                end
            end

            local event = room.logic:getCurrentEvent()
            local move_event = event:searchEvents(GameEvent.MoveCards,1,function (e)
                local pindian_event = e:findParent(GameEvent.Pindian)
                if pindian_event and pindian_event.parent.id == event.id then
                    for _, move in pairs(e.data) do
                        if move.toArea == Card.DiscardPile then
                            return true
                        end
                    end
                end
            end)
            if #move_event ~= 0 then
                room.logic:moveCardsHoldingAreaCheck(ids,move_event[1].id)
            else
                ids = {}
            end
            if pindian.results[target].winner == player then
                if #ids ~= 0 then
                    local use = room:askToUseRealCard(player,{expand_pile=ids,skip=true,pattern=ids,prompt="#mcdh_zhaowendaoyi-use"})
                    if use then
                        use.extra_data = {}
                        use.extra_data.mchd_zhaowendaoyi = true
                        room:useCard(use)
                    end
                end
                local  cards = room:askForCard(target, 2, 999, true, self.name, true, ".", "#mcdh_zhaowendaoyi-recast")
                if #cards > 0  then
                    room:recastCard(cards, target, self.name)
                end
            elseif pindian.results[target].winner == target then
                if #ids ~= 0 then
                    local use =  room:askToUseRealCard(target,{expand_pile=ids,skip=true,pattern=ids,prompt="#mcdh_zhaowendaoyi-use"})
                    if use then
                        use.extra_data = {}
                        use.extra_data.mchd_zhaowendaoyi = true
                        room:useCard(use)
                    end
                end

                local  cards = room:askForCard(player, 2, 999, true, self.name, true, ".", "#mcdh_zhaowendaoyi-recast")
                if #cards > 0  then
                    room:recastCard(cards, player, self.name)
                end
            end
        end
    end ,})

Fk:loadTranslationTable {
    ["mcdh_zhaowendaoyi_other&"] = "朝闻道矣",
    [":mcdh_zhaowendaoyi_other&"] = "出牌阶段限一次，你可以与赫尔昏佐伦拼点:赢的角色可以使用其中一张拼点牌;输的角色可以重铸至少两张牌.",
    ["#mcdh_zhaowendaoyi-recast"] = "朝闻道矣:重铸至多两张牌",
    ["#mcdh_zhaowendaoyi-use"] = "朝闻道矣:使用其中一张拼点牌",
}    

return zhaowendaoyi_other